package com.shigu.admin.common.service;

import com.opentae.core.mybatis.utils.FieldUtil;
import com.opentae.data.mall.beans.ManagerUser;

import com.opentae.data.mall.interfaces.ManagerUserMapper;
import com.shigu.admin.common.vo.OemVO;
import com.shigu.admin.manager.utils.BeanMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * O单系统服务
 */
@Service
public class OemSystemService {

//    @Autowired
//    private MoOperatorMapper moOperatorMapper;

    @Autowired
    private ManagerUserMapper managerUserMapper;

    @Value("${me.company}")
    private String company;

    @Value("${me.logoUrl}")
    private String logoUrl;

    @Value("${me.logoTxt}")
    private String logoTxt;

    /**
     * 查询用户的oem信息
     * @param userId 用户ID
     * @return
     */
    public String selUserOemTag(Long userId){
        if (userId == null) {
            return "default";
        }
        ManagerUser user=managerUserMapper.selectFieldsByPrimaryKey(userId, FieldUtil.codeFields("user_id,oem_tag"));
        if (user == null) {
            return "default";
        }
        return user.getOemTag();
    }
    /**
     * 按tag查oem
     * @param tag
     * @return
     */
    public OemVO selOemByTag(String tag){
//        if (tag == null||"default".equals(tag)) {
//            return selDefaultOem();
//        }
//        MoOperatorExample example=new MoOperatorExample();
//        example.createCriteria().andOemTagEqualTo(tag).andEnabledEqualTo(true);
//        List<MoOperator> oems=moOperatorMapper.selectByExample(example);
//        if (oems.size()==0) {
//            return selDefaultOem();
//        }
//        return BeanMapper.map(oems.get(0),OemVO.class);
        return selDefaultOem();
    }

    /**
     * 默认OEM
     * @return
     */
    public OemVO selDefaultOem(){
        OemVO vo=new OemVO();
        vo.setCompany(company);
        vo.setLogoUrl(logoUrl);
        vo.setLogoTxt(logoTxt);
        vo.setTag("default");
        return vo;
    }
}
